<template>
  <div class="enter_currency">
    <div class="search-box">
      <Row type="flex">
        <Row type="flex"
             justify="start"
             class="search-item-left">
          <Col class="search-item">
          <span class="search-label">会员编号：</span>
          <Input v-model="dataParmas.memberId"
                 @on-keyup="filterSpace"
                 :maxlength="100"
                 placeholder="请输入">
          </Input>
          </Col>
          <Col class="search-item">
          <span class="search-label">会员姓名：</span>
          <Input v-model="dataParmas.memberName"
                 @on-keyup="filterSpace"
                 :maxlength="100"
                 placeholder="请输入">
          </Input>
          </Col>
          <Col class="search-item">
          <Button class="search-btn"
                  type="primary"
                  @click="searchList">查询</Button>
          </Col>
        </Row>
      </Row>
    </div>
    <Table :columns="columns"
           stripe
           :loading="isLoading"
           class="table-list"
           :data="data"></Table>
    <div class="page-box">
      <Page :total="size"
            :current="dataParmas.offset"
            :page-size="dataParmas.limit"
            @on-page-size-change="selectPageNum"
            @on-change="selectPageIndex"
            ref="pages"
            show-total
            show-sizer />
    </div>
  </div>
</template>
<script>
import { shopStockMovein } from '@/api/report/shop'
import { formatDate } from '@/libs/tools'
export default {
  name: 'report_shop_gamecurrency_enter_currency',
  data () {
    return {
      dataParmas: {
        memberId: '',
        memberName: '',
        shopIds: [],
        startDate: '',
        endDate: '',
        cashierType: '',
        cashierId: '',
        offset: 1,
        limit: 10
      },
      isLoading: true,
      totalAmount: 0, // 总存币数
      size: 10,
      dataArr: [],
      data: [
      ],
      columns: [
        {
          title: '时间',
          key: 'createTime'
        },
        {
          title: '会员编号',
          key: 'memberId'
        },
        {
          title: '会员姓名',
          key: 'memberName'
        },
        {
          title: '存币数',
          key: 'amount'
        },
        {
          title: '操作人',
          key: 'creatorName'
        }
      ]
    }
  },
  mounted () {
    let objData = JSON.parse(localStorage.getItem('enterCurrency'))
    this.dataParmas = {
      memberId: '',
      memberName: '',
      shopIds: objData.id,
      startDate: formatDate(new Date(new Date(objData.dayTimes).getTime()), 'yyyy-MM-dd') + ' 00:00:00',
      endDate: formatDate(new Date(new Date(objData.dayTimes).getTime() + 86400000), 'yyyy-MM-dd') + ' 00:00:00',
      cashierType: this.$route.params.id,
      cashierId: objData.cashierId,
      offset: 1,
      limit: 10
    }
    this.getStockMovein()
  },
  methods: {
    searchList () {
      this.getStockMovein()
    },
    // 获取入币数
    getStockMovein () {
      this.totalAmount = 0
      this.isLoading = true
      this.data = []
      shopStockMovein({
        ...this.dataParmas,
        merchantId: this.$store.state.user.merchantId,
        offset: (this.dataParmas.offset - 1) * this.dataParmas.limit,
        limit: this.dataParmas.limit
      }).then((res) => {
        if (res.data.status === 200) {
          this.dataArr = res.data.data
          this.isLoading = false
          if (res.data.data.length) {
            this.dataArr.forEach(ele => {
              this.totalAmount += ele.amount
            })
            this.dataArr.push({
              createTime: '合计',
              amount: this.totalAmount
            })
            this.data = this.dataArr
            this.size = res.data.totalCount
          }
        } else {
          this.isLoading = false
          this.$Message.error(`${res.data.error}`)
        }
      })
    },
    // 选择每页条数
    selectPageNum (PageNum) {
      this.dataParmas.limit = PageNum
      this.getStockMovein()
    },
    // 选择页面
    selectPageIndex (PageIndex) {
      this.dataParmas.offset = PageIndex
      this.getStockMovein()
    },
    filterSpace () {
      this.dataParmas.memberId = this.dataParmas.memberId.replace(/\s+/g, '')
      this.dataParmas.memberName = this.dataParmas.memberName.replace(/\s+/g, '')
    }
  }
}
</script>
